Drug delivery devices such as syringes or ampoules usually comprise a hollow cylinder made of a pharmaceutical glass which is inert and chemically resistant against the drug stored inside, e.g. insulin. The container is sealed by a stopper or bung at one end of the cylinder which can be moved along the longitudinal axis of the cylinder in order to displace the drug and force it out of an outlet end which may be sealed by a piercable membrane. The stopper and the piercable membrane are conventionally made of an elastomere ensuring mechanical tightness under defined pressure conditions and long term germ impermeability.
When automatically dosing drugs, it may be desirable to detect the amount of drug in the container, e.g. by detecting the position of the stopper in the container. Hence a remaining quantity of the drug in the container can be calculated for a given geometry of the medicament container and a given longitudinal position of the stopper. This allows for an automatic dosing of the medicament, e.g. in an electromechanical insulin pen.